﻿//TODO: XNOR Test

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// XNORs two images
    /// </summary>
    public class XNOR : BaseImageFilter, ITwoSourceFilter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="XNOR"/> class.
        /// </summary>
        public XNOR()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="XNOR"/> class.
        /// </summary>
        /// <param name="_xnor">The _xnor.</param>
        internal XNOR(XNOR _xnor)
        {
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            Process((UnsafeBitmap)_bitmap.Clone(), _bitmap);
            return _bitmap;
        }

        /// <summary>
        /// Processes the specified bmpimg.
        /// </summary>
        /// <param name="bmpimg">The bmpimg.</param>
        /// <param name="bmp">The BMP.</param>
        /// <returns></returns>
        public UnsafeBitmap Process(UnsafeBitmap bmpimg, UnsafeBitmap bmp)
		{
            // NANDing of 2 images is done by ANDing 2 images then negating the resultant

			UnsafeBitmap orimg = new XOR().Process( bmpimg, bmp );
            new Invert().Execute(orimg);

			return orimg;
		}

        /// <summary>
        /// Inverts the specified b.
        /// </summary>
        /// <param name="b">The b.</param>
        /// <returns></returns>
		public byte invert( byte b )
		{
			return ( byte )( 255 - b );
		}

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new XNOR(this);
        }
    }
}
